From 505d736e7f6689555cd0f68cd7bc12f726037290 Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc" Date: Fri, 28 Aug 2020 16:40:20 -0500 Subject: [PATCH] New function to find component config checking entry points --- src/pgwui_common/plugin.py | 11 ++++++++++ tests/test_plugin.py | 43 ++++++++++++++++++++++++++++---------- 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/src/pgwui_common/plugin.py b/src/pgwui_common/plugin.py index d5b97a7..9a88175 100644 --- a/src/pgwui_common/plugin.py +++ b/src/pgwui_common/plugin.py @@ -32,6 +32,17 @@ def find_pgwui_components(): pkg_resources.iter_entry_points('pgwui.components')] +def find_pgwui_check_settings(): + '''Return dict of all pgwui.check_setting entry points, keyed by + component + ''' + check_settings = dict() + for entry_point in pkg_resources.iter_entry_points('pgwui.check_settings'): + callable = entry_point.resolve() + check_settings[callable.__name__] = callable + return check_settings + + def component_to_key(component): '''Convert the component to a key used in an ini file's declaration ''' diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 5521436..077f925 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -22,6 +22,23 @@ from pgwui_common import plugin +# Helper classes +class MockEntryPoint(): + def __init__(self, val): + self.__name__ = val + + def resolve(self): + return self + + +class MockPkgResources(): + def __init__(self, entry_points): + self.entry_points = entry_points + + def iter_entry_points(self, *args): + return [MockEntryPoint(name) for name in self.entry_points] + + # find_pgwui_components() def test_find_pgwui_components(monkeypatch): @@ -29,23 +46,27 @@ def test_find_pgwui_components(monkeypatch): ''' entry_points = ['a', 'b', 'c'] - class MockEntryPoint(): - def __init__(self, val): - self.__name__ = val + monkeypatch.setattr( + plugin, 'pkg_resources', MockPkgResources(entry_points)) - def resolve(self): - return self + result = plugin.find_pgwui_components() + + assert result == entry_points - class MockPkgResources(): - def iter_entry_points(*args): - return [MockEntryPoint(name) for name in entry_points] + +# find_pgwui_check_settings +def test_find_pgwui_check_settings(monkeypatch): + '''Returns a dict, keyed by name, of entry points + ''' + entry_points = ['a', 'b', 'c'] monkeypatch.setattr( - plugin, 'pkg_resources', MockPkgResources()) + plugin, 'pkg_resources', MockPkgResources(entry_points)) - result = plugin.find_pgwui_components() + result = plugin.find_pgwui_check_settings() - assert result == entry_points + assert isinstance(result, dict) + assert list(result.keys()).sort() == entry_points.sort() # component_to_key() -- 2.34.1